package com.hhc.controller.appliance_master;

import com.alibaba.fastjson.JSONObject;
import com.hhc.model.ApplianceMaster;
import com.hhc.model.ApplianceMasterExt;
import com.hhc.service.ApplianceMasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/applianceMaster")
public class ApplianceMasterController {
    @Autowired
    private ApplianceMasterService applianceMasterService;

    @RequestMapping(value = "/addAppliance", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject addAppliance(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMaster applianceMaster = JSONObject.parseObject(data, ApplianceMaster.class);
        jsonObject = applianceMasterService.addAppliance(applianceMaster);
        return jsonObject;
    }

    @RequestMapping(value = "/queryApplianceList", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject queryApplianceList(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMasterExt applianceMasterExt = JSONObject.parseObject(data, ApplianceMasterExt.class);
        jsonObject = applianceMasterService.queryApplianceList(applianceMasterExt);
        return jsonObject;
    }

    @RequestMapping(value = "/deleteAppliance", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteAppliance(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMaster applianceMaster = JSONObject.parseObject(data, ApplianceMaster.class);
        jsonObject = applianceMasterService.deleteAppliance(applianceMaster);
        return jsonObject;
    }

    @RequestMapping(value = "/updateApplianceName", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateApplianceName(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMaster applianceMaster = JSONObject.parseObject(data, ApplianceMaster.class);
        jsonObject = applianceMasterService.updateApplianceName(applianceMaster);
        return jsonObject;
    }

    @RequestMapping(value = "/getApplianceMessage", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject getApplianceMessage(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMasterExt applianceMasterExt = JSONObject.parseObject(data, ApplianceMasterExt.class);
        jsonObject = applianceMasterService.getApplianceMessage(applianceMasterExt);
        return jsonObject;
    }

    @RequestMapping(value = "/addSceneAppliance", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject addSceneAppliance(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMaster applianceMaster = JSONObject.parseObject(data, ApplianceMaster.class);
        jsonObject = applianceMasterService.addSceneAppliance(applianceMaster);
        return jsonObject;
    }

    @RequestMapping(value = "/deleteSceneAppliance", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteSceneAppliance(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMaster applianceMaster = JSONObject.parseObject(data, ApplianceMaster.class);
        jsonObject = applianceMasterService.deleteSceneAppliance(applianceMaster);
        return jsonObject;
    }


    @RequestMapping(value = "/isApplianceExist", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject isApplianceExist(@RequestBody String data) {
        JSONObject jsonObject;
        ApplianceMaster applianceMaster = JSONObject.parseObject(data, ApplianceMaster.class);
        jsonObject = applianceMasterService.isApplianceExist(applianceMaster);
        return jsonObject;
    }
}
